<?php
namespace Service\Library;

class LibTemplate
{
    private $tpl_path;
    private $vars = [];

    public function __construct($tpl_path)
    {
        $this->tpl_path = $tpl_path;
    }

    public function assign($k, $v)
    {
        $this->vars[$k] = $v;
    }

    public function display($tpl_name)
    {
        extract($this->vars, EXTR_SKIP);

        $tpl_file = "{$this->tpl_path}/{$tpl_name}.php";
        if(file_exists($tpl_file)) {
            include $tpl_file;
        } else {
            echo "未找到相应模板：{$tpl_file}";
        }
    }

    public function include($tpl_name)
    {
        $this->display($tpl_name);
    }

    public function __destruct()
    {
        // ...
    }
}